﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2012/01/16
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Xml;

namespace Luminji.Core.Web.Rss
{
    public class RssHelper
    {
        public static IList<RssItem> GetRsses(string url)
        {
            IList<RssItem> rssItems = new List<RssItem>();
            Stream stream = WebContentHelper.GetWebStream(url);
            XmlReader response = null;
            try
            {
                response = XmlReader.Create(stream);
                SyndicationFeed feeds = SyndicationFeed.Load(response);
                foreach (SyndicationItem f in feeds.Items)
                {
                    RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri);
                    rssItems.Add(rssItem);
                }
                return rssItems;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
    }
}
